﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.SqlTypes;


namespace LibrarySystem
{
    public partial class Form2 : Form
    {
        string NAME_USER;
        //=====================================
        SqlConnection Connection_Main = new SqlConnection();
        //string str;
        AppManager LIB = new AppManager();
        int counter = 0;
        public Form2()
        {
            InitializeComponent();
            //str = "integrated security=SSPI;" + "data source='JASMINE-PC';" + "initial catalog='alssafa'";
            //Connection_Main.ConnectionString = str;
            //Connection_Main.Open();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label2.Text = DateTime.Now.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1 F1 = new Form1();
            F1.Show();
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {


            if (counter > 3)
            {
                MessageBox.Show("قمت بإدخال بيانات خاطئة 5 مرات؛ سيتم إغلاق البرنامج!");
                Application.Exit();
            }

            if (username1.Text != "")
            {
                if (password1.Text != "")
                {
                    LIB.GridDisplay(dataGridView1, "EMPLOYEE", "select * from alssafa.dbo.EMPLOYEE where الإسم = '" + username1.Text + "'");
                    if (dataGridView1.RowCount > 1)
                    {
                        LIB.ComboDisplay(comboBox1, "select * from alssafa.dbo.EMPLOYEE where الإسم = '" + username1.Text + "'", "EMPLOYEE", "كلمة_المرور");
                        if (password1.Text == comboBox1.Text)
                        {
                            LIB.ComboDisplay(comboBox2, "select * from alssafa.dbo.EMPLOYEE where الإسم = '" + username1.Text + "' AND كلمة_المرور = '" + password1.Text + "'", "EMPLOYEE", "الوظيفة");
                            if (comboBox2.Text == "الإدارة")
                            {
                                NAME_USER = username1.Text;
                                Director_form DF = new Director_form(NAME_USER);
                                DF.Show();
                                this.Hide();
                                MessageBox.Show("أهلا وسهلا .... سعادة المدير");

                            }
                            else if (comboBox2.Text == "المحاسبة")
                            {
                                NAME_USER = username1.Text;
                                Accounting_form AC = new Accounting_form(NAME_USER);
                                AC.Show();
                                this.Hide();
                                MessageBox.Show("تم الدخول ..... أهلا وسهلا");
                            }
                        }
                        else
                        {
                            MessageBox.Show("كلمة المرور غير صحيحة");
                            counter++;
                        }

                    }
                    else
                    {
                        MessageBox.Show("اسم المستخدم غير موجود");
                        counter++;
                    }
                }
                else
                {
                    MessageBox.Show("أدخل كلمة المرور ");
                    counter++;
                }
            }
            else
                MessageBox.Show("أدخل اسم المستخدم ");


        }
    }
}
